/*******************************************************************************
*  file    : qloggercontext.cpp
*  created : 02.05.2013
*  author  : 
*******************************************************************************/

#include "qloggercontext.hpp"
#include "qlogger_.hpp"

QLoggerContext::~QLoggerContext()
{
    if(logger_)
        logger_->log(category_,msg_,file_,line_,function_);
    if(stream_)
        delete stream_;
}

QLoggerContext& QLoggerContext::operator<<(const QString& str)
{
    if(stream_)
        (*stream_) << str;
    else
        msg_ += str;
    return (*this);
}
QLoggerContext& QLoggerContext::operator<<(int i)
{
    if(stream_)
        (*stream_) << i;
    else
        msg_ += QString::number(i);
    return (*this);
}

QLoggerContext&QLoggerContext::operator<<(unsigned int i)
{
    if(stream_)
        (*stream_) << i;
    else
        msg_ += QString::number(i);
    return (*this);
}
QLoggerContext& QLoggerContext::operator<<(double d)
{
    if(stream_)
        (*stream_) << d;
    else
        msg_ += QString::number(d);
    return (*this);
}

QLoggerContext&QLoggerContext::debug(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelDebug;
    return (*this);
}

QLoggerContext&QLoggerContext::info(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelInfo;
    return (*this);
}

QLoggerContext&QLoggerContext::warn(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelWarn;
    return (*this);
}

QLoggerContext&QLoggerContext::error(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelError;
    return (*this);
}

QLoggerContext&QLoggerContext::fatal(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelFatal;
    return (*this);
}

QLoggerContext&QLoggerContext::critical(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelCritical;
    return (*this);
}

QLoggerContext&QLoggerContext::exception(QLogger* l, const QString& msg)
{
    logger_ = l;
    msg_ = msg;
    category_ = LevelException;
    return (*this);
}

